package com.zjut.an.config.manager;

import java.util.List;

import javax.annotation.Resource;

import com.zjut.an.config.dao.AnConfig;
import com.zjut.an.config.dao.AnConfigDAO;
import com.zjut.an.util.module.PageModule;


public class AnConfigManager {

	@Resource(name = "AnConfigDAO")
	private AnConfigDAO dao;
	
	public void addData(AnConfig obj) {	
		dao.save(obj);
	}
	
	public void updateData(AnConfig obj) {
		dao.update(obj);
	}
	
	public void deleteData(AnConfig obj) {
		dao.delete(obj);
	}

	public void deleteDatas(List<AnConfig> objllegeList) {
		for (AnConfig AnConfig : objllegeList) {
			dao.delete(AnConfig);
		}
	}
	
	public PageModule getDataByInstance (int pageNumber,int pageSize, String sort, String order, AnConfig obj) {
		return dao.findByInstance(pageNumber, pageSize, sort, order, obj);
	}
	
	public List getDatas() {
		return dao.findAll();
	}

	public AnConfig getData(int objId) {
		return dao.findById(objId);
	}
	
	public String getSingleConfigInfoByName(String coName) {
		String info = "";
		//System.out.println("@@@@ dao "+dao);
		List configlist = dao.findByCoName(coName);
		if (configlist.size()>0) info = ((AnConfig)configlist.get(0)).getCoValue();
		//System.out.println("@@@@ info "+info);
		return info;
	}
	
	public AnConfig getConfigInfoByName(String coName) {
		List configlist = dao.findByCoName(coName);
		if (configlist.size()>0) return (AnConfig)configlist.get(0);
		return null;
	}

	public List getConfigsInfoByName(String coName) {
		return dao.findByCoName(coName);
	}

	public List getConfigsInfoByClass(String coClass) {
		AnConfig obj = new AnConfig();
		obj.setCoClass(coClass);
		return dao.findByInstance(1, 100, "coOrder", "asc", obj).getObjects();
		//return dao.findByCoClass(coClass);
	}
}
